import random
import unittest
import ConfigParser

import sys
sys.path.append('..')

from DBWrapper import DBWrapper
from MarketDepthItem import MarketDepthItem
from Quote import Quote
from datetime import datetime

class IBMsg(object):    
    def __init__(self, tickerId, position, operation, side, price, size): 
        self.tickerId   = tickerId
        self.position   = position
        self.operation  = operation
        self.side       = side
        self.price      = price
        self.size       = size


class MarketDepthItemTest(unittest.TestCase):

    def setUp(self):
        config = ConfigParser.ConfigParser()
        config.read('../cfg/config.cfg')        
        self.db = DBWrapper(config.get('Database', 'testdb'))

    def test_addmktdepth(self):
        ibmsg = IBMsg(1, 2, 3, 4, 5, 6)
        self.db.add(MarketDepthItem(ibmsg))
        
        items = self.db.getMarketDepthItems() 
        self.assertIsNotNone(items)
        self.assertEqual(items[-1].size, ibmsg.size)
    

if __name__ == '__main__':
    unittest.main()